package com.aseo.business;

import java.sql.Timestamp;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;
import javax.validation.ConstraintViolation;

import org.springframework.stereotype.Service;

import com.aseo.exception.ConstraintViolationException;
import com.aseo.model.dao.Dao;
import com.aseo.model.entity.AccionReclamo;

//@Service
public class AccionReclamoManager {

	@Resource  
	private Dao dao;
	
	public AccionReclamo newAccionReclamo() {  
		return new AccionReclamo();  
	}  
	  
	public void persist(AccionReclamo accionReclamo) {
		accionReclamo.setFechaHora(new Timestamp(System.currentTimeMillis()));
		dao.persist(accionReclamo);
	}
	  

	public List<AccionReclamo> getAccionReclamos() {  
		final List<AccionReclamo> list = dao.find(AccionReclamo.class);  
	    return list;
	}
	
	public AccionReclamo get(Long idAccionReclamo) {
		return dao.get(AccionReclamo.class, idAccionReclamo);
	}
	
	public void validate(AccionReclamo accionReclamo) throws ConstraintViolationException {

		Set<ConstraintViolation<AccionReclamo>> constraintViolations = dao.validate(accionReclamo);
		
		for (ConstraintViolation<AccionReclamo> constraintViolation : constraintViolations) {
			throw new ConstraintViolationException(constraintViolation.getMessage());
		}
		
	}

}